/**
 * 
 */
package com.yuqinyi.blog.service;

import java.time.LocalDate;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.yuqinyi.blog.domain.User;

/**
 * @author yuqy
 *
 */
@Component("userService")
@Transactional
public class UserServiceImpl implements UserService {

	private UserRepository userRepository;

	UserServiceImpl(UserRepository userRepository) {
		this.userRepository = userRepository;
	}

	/************************** create ********************************/
	@Override
	public User save(User user) {
		return userRepository.save(user);
	}

	/************************** read ********************************/
	@Override
	public List<User> findByAndSort(String lastName, Sort sort) {
		return userRepository.findByAndSort(lastName, sort);
	}

	@Override
	public User findByIdCard(String idCard) {
		return userRepository.findByIdCard(idCard);
	}

	@Override
	public User findByIdCard2(String idCard) {
		return userRepository.findByIdCard2(idCard);
	}

	@Override
	public User findByIdCard3(String idCard) {
		return userRepository.findByIdCard3(idCard);
	}

	@Override
	public Page<User> findByLastNameWithPageable(String lastName, Pageable pageable) {
		return userRepository.findByLastNameWithPageable(lastName, pageable);
	}

	@Override
	public List<User> findByFirstNameOrLastName(String firstName, String lastName) {
		return userRepository.findByFirstNameOrLastName(firstName, lastName);
	}

	@Override
	public List<User> findByDateOfBirth(@Param("date") LocalDate date) {
		return userRepository.findByDateOfBirth(date);
	}

	@Override
	public List<User> findAll(Sort sort) {
		return userRepository.findAll(sort);
	}

	/************************** update ********************************/
	@Override
	public int updateUser(String firstName, String idCard) {
		return userRepository.updateUser(firstName, idCard);
	}

	/************************** delete ********************************/
	@Override
	public void deleteByIdCard(String idCard) {
		userRepository.deleteByIdCard(idCard);
	}

	@Override
	public void deleteByIdCard2(String idCard) {
		userRepository.deleteByIdCard2(idCard);
	}

	@Override
	public void deleteById(Long id) {
		userRepository.deleteById(id);
	}

//	@Override
//	public User save(User user) {
//		return null;
//	}
//
//	@Override
//	public List<User> findByAndSort(String lastName, Sort sort) {
//		// TODO Auto-generated method stub
//		return null;
//	}
//
//	@Override
//	public User findByIdCard(String idCard) {
//		// TODO Auto-generated method stub
//		return null;
//	}
//
//	@Override
//	public User findByIdCard2(String idCard) {
//		// TODO Auto-generated method stub
//		return null;
//	}
//
//	@Override
//	public User findByIdCard3(String idCard) {
//		// TODO Auto-generated method stub
//		return null;
//	}
//
//	@Override
//	public Page<User> findByLastNameWithPageable(String lastName, Pageable pageable) {
//		// TODO Auto-generated method stub
//		return null;
//	}
//
//	@Override
//	public List<User> findByFirstNameOrLastName(String firstName, String lastName) {
//		// TODO Auto-generated method stub
//		return null;
//	}
//
//	@Override
//	public List<User> findByDateOfBirth(LocalDate date) {
//		// TODO Auto-generated method stub
//		return null;
//	}
//
//	@Override
//	public List<User> findAll(Sort sort) {
//		// TODO Auto-generated method stub
//		return null;
//	}
//
//	@Override
//	public int updateUser(String firstName, String idCard) {
//		// TODO Auto-generated method stub
//		return 0;
//	}
//
//	@Override
//	public void deleteByIdCard(String idCard) {
//		// TODO Auto-generated method stub
//
//	}
//
//	@Override
//	public void deleteByIdCard2(String idCard) {
//		// TODO Auto-generated method stub
//
//	}
//
//	@Override
//	public void deleteById(Long id) {
//		// TODO Auto-generated method stub
//
//	}

}
